package com.nkzy.controller;

import com.nkzy.pojo.User;
import com.nkzy.pojo.Result;
import com.nkzy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping
    public Result insertUser(@RequestBody User user) {
        userService.insertUser(user);
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    public Result deleteUserById(@PathVariable Long id) {
        userService.deleteUserById(id);
        return Result.ok();
    }

    @PutMapping
    public Result updateUser(@RequestBody User user) {
        userService.updateUser(user);
        return Result.ok();
    }

    @GetMapping("/{id}")
    public Result selectUserById(@PathVariable Long id) {
        User user = userService.selectUserById(id);
        return Result.ok(user);
    }

    @GetMapping("/list")
    public Result selectAllUsers() {
        List<User> users = userService.selectAllUsers();
        return Result.ok(users);
    }

    @GetMapping("/ids")
    public Result selectUsersByIds(@RequestParam List<Long> ids) {
        List<User> users = userService.selectUsersByIds(ids);
        return Result.ok(users);
    }
}